var api = require("./../../../../source/js/service.js")
avalon.component('ms-home-activity',{
	template:require("./activity.html"),
	defaults:{
		type:"",
		user:{},
		opts:{},
		count:0,
		activities:[],
		emptyActivity:{
			img:'',
			name:"暂无更多",
			organizer:"暂无主办方"
		},
		getActivities:function(){
			var that = this
			return api.getItems({
				method:api.getActivity,
				query:{
					PageSize:that.opts.pageSize,
					status:that.opts.status
				}
			},function(res){
				if(res.success){
					that.count = res.data.query.recordCount
					that.activities = res.data.list
					if(that.activities.length<=2){
						that.activities.push(that.emptyActivity)
					}
				}
			})
		},
		onInit:function(){
			var that = this
			// this.user = window.duxStore.getState().user
			window.duxStore.subscribe(function(){
				console.log('*******************')
				if(that.user.name!=window.duxStore.getState().user.name){
					that.user = window.duxStore.getState().user
					console.log(window.duxStore.getState().user,'zzzz')
				}
			})
			this.emptyActivity.name += this.opts.status?'回顾':'活动'
			return this.getActivities()
		},
		onReady:function(){
			// this.$watch('setting',function(user){
			// 	avalon.log(user,'wwwwwww')
			// 	that.user = user
			// })
			// window.duxStore.subscribe(function(){
			// 	if(that.user.name!=window.duxStore.getState().user.name){
			// 		that.user = window.duxStore.getState().user
			// 		avalon.log(that.user,'zzzz')
			// 	}
			// })
			// var that = this
			// window.duxStore.subscribe(function(){
			// 	console.log('*******************')
			// 	if(that.user.name!=window.duxStore.getState().user.name){
			// 		that.user = window.duxStore.getState().user
			// 		console.log(that.user,'zzzz')
			// 	}
			// })
		}
	}
})